#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# Author: xiyoulaoyuanjia
#         xiyoulaoyuanjia@gmail.com

import os
import tornado.web
import jinja2
import sys

from handlers import handlers
from db import *
import config
import logging

class Application(tornado.web.Application):
    def __init__(self, message_queue=None):
        logger = logging.getLogger('webui') 
        logger.debug('tornado Application init begin')
        setting = dict(
            template_path = os.path.join(os.path.dirname(__file__), 'tpl'),
            static_path = os.path.join(os.path.dirname(__file__), 'static'),
            debug = config.debug,
#            gzip = config.gzip,
#            cookie_secret = config.cookie_secret,
#            login_url = '/login',
            )

        super(Application,self).__init__(handlers, **setting)

        self.jinja_env = jinja2.Environment(
            loader= jinja2.FileSystemLoader(setting['template_path']),
#           extensions = ['jinja2.ext.autoescape', 'jinja2.ext.loopcontrals', ],
#            autoescape = True,
#            auto_reload = config.debug,
            )

        self.jinja_env.globals.update({
            'config': config,
#            'format_date': utils.format_date,
            })

#        self.jinja_env.filters.update(ui_methods)

        class DB(object):
			pass
#            user = db.UserDB()
#            book = db.BookDB()

        self.db = DB

        self.message_queue = message_queue
        logger.debug('tornado Application init end')
